#include "junix.h"

template<typename T = int>
struct node {
	typedef T value_type;
	typedef node<T> self;
	T data;
	node<T>  *next;
	
	node ():next(0){}
	node (const T& t,node<T>* n = NULL):data(t),next(n){}
   void set_next (node<T>* n) 
	{ next = n; }

	void print() {
		std::cout<<data<<" ";
		if (next)
				  next->print(); 
	}
};
//////////////////////////////////////////////////////////////////////////////////////////
//错误： default template arguments may not be used in function templates
//////////////////////////////////////////////////////////////////////////////////////////
template <typename T /* =int */ >
node<T>* create_list(){
		  node<T> *head = new node<T>(1);
		  node<T> *prev = head;
		  for (int i=2;i<=10;i++) {
					 node<T> *tmp = new node<T>(i);
					 prev->set_next(tmp);
					 prev = tmp;
		  }
		
		return head;
}

template <typename T>
node<T>* reverse(node<T>* head){
	if (!head->next) return head;

	node<T> *nh = reverse<T>(head->next);
	node<T> *p = nh;
	while (p->next) { p = p->next; }
	p->set_next(head);
	head->set_next(NULL);
	return nh;
}

//char *reverse_str(char *p) {}

int main() {
	node<int> *head = create_list<int>();
	head->print();
	std::cout<<std::endl;
	head = reverse(head);
	head->print();
	std::cout<<std::endl;

}
